package com.push_label.common;


import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private int code;
    private String message;
    private T data;

    public Result() {
    }


    public Result<T> code(int code) {
        this.code = code;
        return this;
    }

    public Result<T> message(String message) {
        this.message = message;
        return this;
    }

    public Result<T> data(T data) {
        this.data = data;
        return this;
    }

    public static <T> Result<T> create() {
        return new Result<T>();
    }

    public static <T> Result<T> success() {
        return Result.<T>create().code(200).message("success");
    }


    public static <T> Result<T> success(T data) {
        return Result.<T>create().code(200).message("success").data(data);
    }

    public static <T> Result<T> fail() {
        return Result.<T>create().code(500).message("fail");
    }

    public static <T> Result<T> fail(String message) {
        return Result.<T>create().code(500).message(message);
    }

    public static <T> Result<T> fail(int code, String message) {
        return Result.<T>create().code(code).message(message);
    }

}
